#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef pair < int , int > pii;
typedef vector < int > vec;
typedef vector < pii > veg;
typedef long long ll;
typedef double db;
typedef unsigned int uint;

int read() {
    int x = 0; bool f = 0; char ch = getchar(); while(!isdigit(ch)) f |= ch =='-',ch = getchar();
    while(isdigit(ch)) x = x * 10 + (ch ^ 48),ch = getchar(); return f ? -x : x;
}

const int N = 4e5 + 10;
const int V = 1e9 + 7;

mt19937 rnd(19491001);

uint C[15][15],a[N];
int n;

namespace treap {
    const int N = 4e5 + 10;
    int pri[N],siz[N],ndn,rt,ch[N][2];
    uint ans[N][15],va[N];
    uint pt[15];
    int nd(uint val) { int x = ++ndn; for(int i = 0;i <= 10;i++) ans[x][i] = val; pri[x] = rnd() % V; siz[x] = 1; va[x] = val; return x; }
    void pu(int x) {
	siz[x] = siz[ch[x][0]] + siz[ch[x][1]] + 1; pt[0] = 1; for(int i = 1;i <= 10;i++) pt[i] = pt[i - 1] * (siz[ch[x][0]] + 1);
	for(int i = 0;i <= 10;i++) {
	    ans[x][i] = ans[ch[x][0]][i] + va[x] * pt[i];
	    for(int j = 0;j <= i;j++) ans[x][i] = ans[x][i] + ans[ch[x][1]][j] * C[i][j] * pt[i - j];
	}
    }
    int merge(int x,int y) {
	if(!x || !y) return x | y;
	if(pri[x] < pri[y]) return ch[x][1] = merge(ch[x][1],y),pu(x),x;
	else return ch[y][0] = merge(x,ch[y][0]),pu(y),y;
    }
    void split(int cur,int k,int &x,int &y) {
	if(!cur) return x = y = 0,void();
	if(siz[ch[cur][0]] < k) x = cur,split(ch[cur][1],k - siz[ch[cur][0]] - 1,ch[x][1],y),pu(x);
	else y = cur,split(ch[cur][0],k,x,ch[y][0]),pu(y);
    }
    int a,b,c,d;
    uint res;
    void insert(int pos,uint x) { split(rt,pos,a,b); rt = merge(merge(a,nd(x)),b); }
    void del(int pos) { split(rt,pos,a,b); split(b,1,c,d); rt = merge(a,d); }
    uint getans(int l,int r,int k) { split(rt,l,a,b); split(b,r - l + 1,c,d); res = ans[c][k]; b = merge(c,d); rt = merge(a,b); return res; }
    void change(int pos,uint val) { split(rt,pos,a,b); split(b,1,c,d); va[c] = val; pu(c); rt = merge(a,merge(c,d)); }
}

int main() {
#ifndef ONLINE_JUDGE
    freopen("1.in","r",stdin);
#endif
    n = in; for(int i = 0;i <= 10;i++) C[i][0] = 1; for(int i = 1;i <= 10;i++) for(int j = 1;j <= i;j++) C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
    for(int i = 1;i <= n;i++) scanf("%u",&a[i]),treap :: rt = treap :: merge(treap :: rt,treap :: nd(a[i]));
    int Q = in;
    while(Q--) {
	char op = getchar(); while(!isalpha(op)) op = getchar();
	if(op == 'I') {
	    int pos = in; uint val; scanf("%u",&val); treap :: insert(pos,val);
	} else if (op == 'D') {
	    int pos = in; treap :: del(pos);
	} else if (op == 'R') {
	    int pos = in; uint val; scanf("%u",&val); treap :: change(pos,val);
	} else {
	    int l = in,r = in,k = in; printf("%u\n",treap :: getans(l,r,k));
	}
    } return 0;
}
